﻿<CodeSnippetTabbed>
    <CodeSnippetTabPage Text="Razor">@(@"
<DxDataGrid ...
            Data=""@SupplierService.Suppliers""
            RowRemovingAsync=""@OnRowRemoving""
            RowUpdatingAsync=""@OnRowUpdating""
            RowInsertingAsync=""@OnRowInserting""
            InitNewRow=""@OnInitNewRow""
            EditMode=""@CurrentEditMode"">
    <DxDataGridCommandColumn Width=""100px"" />
    <DxDataGridColumn Field=""@nameof(Supplier.SupplierName)"" />
    <DxDataGridComboBoxColumn Field=""@nameof(Supplier.SupplierCategoryID)""
                              Caption=""Category""
                              Data=""@SupplierService.SupplierCategories""
                              ValueFieldName=""@nameof(SupplierCategory.SupplierCategoryID)""
                              TextFieldName=""@nameof(SupplierCategory.SupplierCategoryName)"" />
    <DxDataGridComboBoxColumn Field=""@nameof(Supplier.DeliveryMethodID)""
                              Caption=""Delivery Method""
                              Data=""@SupplierService.DeliveryMethods""
                              ValueFieldName=""@nameof(DeliveryMethod.DeliveryMethodID)""
                              TextFieldName=""@nameof(DeliveryMethod.DeliveryMethodName)"" />
    <DxDataGridColumn Field=""@nameof(Supplier.PhoneNumber)"" />
    <DxDataGridColumn Field=""@nameof(Supplier.BankAccountBranch)"" />
    <DxDataGridColumn Field=""@nameof(Supplier.BankAccountNumber)"" />
</DxDataGrid>

@code {
    DataGridEditMode CurrentEditMode { get; set; } = DataGridEditMode.EditForm;
    Task OnRowRemoving(Supplier dataItem) {
        return SupplierService.Remove(dataItem);
    }
    Task OnRowUpdating(Supplier dataItem, IDictionary<string, object> newValue) {
        return SupplierService.Update(dataItem, newValue);
    }
    Task OnRowInserting(IDictionary<string, object> newValue) {
        return SupplierService.Insert(newValue);
    }
    Task OnInitNewRow(Dictionary<string, object> values) {
        values.Add(""SupplierCategoryID"", 1);
        values.Add(""DeliveryMethodID"", 1);
        values.Add(""PhoneNumber"", ""(000) 000-0000"");
        values.Add(""BankAccountNumber"", ""0000000000"");
        ...
        return Task.CompletedTask;
    }
    ...
}")</CodeSnippetTabPage>
</CodeSnippetTabbed>
